package cn.cqie.frame.controller;


import cn.cqie.frame.bo.query.QueryStudentBo;
import cn.cqie.frame.bo.query.QueryUserListReqBo;
import cn.cqie.frame.entity.Emp;
import cn.cqie.frame.entity.Student;
import cn.cqie.frame.service.EmpService;
import cn.cqie.frame.service.StudentService;
import cn.cqie.frame.utils.MyPageHelper;
import cn.cqie.frame.vo.EmpVo;
import cn.cqie.frame.vo.ResultVo;
import cn.cqie.frame.vo.UserVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * <p>
 * 学生 前端控制器
 * </p>
 *
 * @author XYHL
 * @since 2021-10-09
 */
@RestController
@Api("学生管理")
public class StudentController {
    @Autowired
    private StudentService studentService;

    /**
     * 新增学生信息
     * @param bo
     * @return
     */
    @ApiOperation("新增学生信息")
    @PostMapping(value = "/student/saveOrUpdateStudent")
    public ResultVo<Void> saveOrUpdateStudent(@Valid @RequestBody Student bo) {
        Boolean aBoolean = studentService.saveStudent(bo);
        return aBoolean ? ResultVo.success() : ResultVo.error("插入失败");
    }

    /**
     * 更新学生信息
     * @param bo
     * @return
     */
    @ApiOperation("更新学生信息")
    @PostMapping(value = "/student/updateStudent")
    public ResultVo<Void> updateStudent(@RequestBody Student bo) {
        Boolean aBoolean = studentService.updateStudent(bo);
        return aBoolean ? ResultVo.success() : ResultVo.error("更新失败");
    }

    /**
     * 删除学生
     * @param studentId
     * @return
     */
    @ApiOperation("删除学生")
    @DeleteMapping("/student/deleteStudent/{studentId}")
    public ResultVo<Void> delete(@PathVariable Integer studentId) {
        Boolean aBoolean = studentService.delete(studentId);
        return aBoolean ? ResultVo.success() : ResultVo.error("删除失败");
    }

    /**
     * 查询学生信息分页
     * @param bo
     * @return
     */
    @ApiOperation("查询学生信息分页")
    @GetMapping(value = "/student/studentInfoPage")
    public ResultVo<PageInfo<UserVo>> getPageList(QueryStudentBo bo) {
        return ResultVo.success(MyPageHelper.returnPage(studentService.list(bo)));
    }

    /**
     * 下载模板
     * @return
     */
    @ApiOperation("下载模板")
    @PostMapping(value = "/student/downloadTemplate")
    public ResultVo<Void> downloadTemplate() {
        studentService.downloadTemplate();
        return null;
    }

    /**
     * 批量导入
     * @param file
     * @return
     * @throws Exception
     */
    @ApiOperation("批量导入")
    @PostMapping(value = "/student/importExcel")
    public ResultVo<Void> importExcel(@RequestParam("file") MultipartFile file) throws Exception {
        Boolean aBoolean = studentService.importExcel(file);
        return aBoolean ? ResultVo.success() : ResultVo.error("导入失败");
    }
}

